const path = require('path')

function resolve(dir) {
  return path.join(__dirname, '.', dir)
}

module.exports = {
  // lintOnSave: process.env.NODE_ENV !== "production",
  runtimeCompiler: true,
  publicPath: '/',
  chainWebpack: (config) => {
    config.module.rules.delete('svg') // 重点:删除默认配置中处理svg,
    config.resolve.alias.set('@', resolve('src'))
    config.module.rules.delete('svg')
    config.module
      .rule('svg-smart')
      .test(/\.svg$/)
      .include.add(resolve('src/config/icons')) // 处理svg目录
      .end()
      .use('svg-sprite-loader')
      .loader('svg-sprite-loader')
      .options({
        symbolId: 'icon-[name]'
      })
    config.optimization.minimizer('terser').tap((args) => {
      const env = process.env.DEP_ENV
      if (env === 'production') {
        args[0].terserOptions.compress.drop_console = false
        args[0].terserOptions.compress.drop_debugger = true
        args[0].sourceMap = false
        return args
      } else {
        args[0].terserOptions.compress.drop_console = false
        args[0].terserOptions.compress.drop_debugger = false
        args[0].sourceMap = true
        return args
      }
    })
  },
  devServer: {
    // proxy: {
    //   "/apis": {
    //     target: "http://192.168.0.11/",
    //     changeOrigin: true
    //   }
    // },
    disableHostCheck: true,
    // hotOnly:false,
    port: '3002'
  },
  css: {
    //查看CSS属于哪个css文件
    sourceMap: true
  }
}
